package com.sptpc.qimoxiangmu.controller;


import com.sptpc.qimoxiangmu.controller.request.UserRequest;
import com.sptpc.qimoxiangmu.model.User;
import com.sptpc.qimoxiangmu.model.vo.UserVo;
import com.sptpc.qimoxiangmu.service.UserService;
import com.sptpc.qimoxiangmu.util.ServerResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    //user的插入
    @PostMapping(value ="/save",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)//表单形式，x.www.urlencoded，成功
    @ResponseBody
    public ServerResponse getUser(@RequestParam String user,
                                  @RequestParam String password
                                      ) {
        return ServerResponse.createBySuccess( userService.saveUser(user,password)) ;
    }

    //user的更新
    @PostMapping(value = "/update",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    @ResponseBody
    public ServerResponse update(UserVo userVo) {
        return ServerResponse.createBySuccess(userService.update(userVo));
    }



}
